package com.naizhuai.ui.task.multtype;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.naizhuai.R;
import com.naizhuai.ui.entity.Task.TaskFlowItem;
import com.naizhuai.ui.entity.Task.TaskFlowList;
import com.naizhuai.ui.entity.mainbusiness.ActionShowMainItemBean;
import com.naizhuai.ui.task.adapter.TaskFlowAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.drakeet.multitype.ItemViewBinder;

/**
 * @author：lichenxi
 * @date 2018/5/9 16
 * email：525603977@qq.com
 * Fighting
 */
public class StepShowViewBinder extends ItemViewBinder<TaskFlowList, StepShowViewBinder.ViewHolder> {
    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_horizontal_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull TaskFlowList taskFlowList) {
        holder.setFlows(taskFlowList.posts);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.post_list)
        RecyclerView recyclerView;
        TaskFlowAdapter adapter;
        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            LinearLayoutManager layoutManager = new LinearLayoutManager(itemView.getContext());
            layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            recyclerView.setLayoutManager(layoutManager);
//            new PagerSnapHelper().attachToRecyclerView(recyclerView);
            adapter = new TaskFlowAdapter(itemView.getContext());
            recyclerView.setAdapter(adapter);
        }

        public void setFlows(List<TaskFlowItem> list){
            adapter.setActionList(list);
            adapter.notifyDataSetChanged();
        }
    }
}
